<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item><i class="el-icon-date"></i> 系统工具</el-breadcrumb-item>
                <el-breadcrumb-item>修改密码</el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div>
                <el-row class="mt20">
                    <el-col :span="4"><span><span class="red">*</span>旧密码：</span></el-col>
                    <el-col :span="4"><el-input v-model="oldPwd" type="password"></el-input></el-col>
                </el-row>
                <el-row class="mt20">
                    <el-col :span="4"><span><span class="red">*</span>新密码：</span></el-col>
                    <el-col :span="4"><el-input v-model="newPwd" type="password"></el-input></el-col>
                </el-row>
                <el-row class="mt20">
                    <el-col :span="4"><span><span class="red">*</span>确认密码：</span></el-col>
                    <el-col :span="4"><el-input v-model="confirmPwd" type="password"></el-input></el-col>
                </el-row>
                <div class="btn-container">
                    <el-button type="primary" @click="updatePwd" :loading="btnloading">确定</el-button>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import { mapState } from 'vuex'
export default {
    data() {
        return {
            oldPwd:"",
            newPwd:"",
            confirmPwd:"",
            btnloading: false
        }
    },
    mounted(){
        if(localStorage.getItem('pageType') == 0) {
            this.$router.push({ path:'/user' });
        }
    },
    computed: mapState({
        msg: state => state.user.msg
    }),
    methods:{
        updatePwd() {
            if(this.oldPwd == "") {
                this.$message('请输入旧密码');
            }else if(this.newPwd == "") {
                this.$message('请输入新密码');
            }else if(this.newPwd !== this.confirmPwd) {
                this.$message('确认密码和新密码不同，请重新输入');
            }else{
                this.btnloading = true;
                this.$store.dispatch('updatePassword',{
                    newPwd: this.newPwd,
                    oldPwd: this.oldPwd,
                    sessionId: localStorage.getItem('sessionId')
                }).then(() => {
                    this.btnloading = false;
                    this.$message(this.msg);
                })
            }  
        }
    }
}
</script>
<style>
input::-webkit-outer-spin-button,
    input::-webkit-inner-spin-button {
        -webkit-appearance: none;
    }
    input[type="number"]{
        -moz-appearance: textfield;
    }
</style>

